using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GCGM
{
	public partial class Tolerance : Form
	{
		ListBox m_lBox;
		List<Toler> m_List;

		public Tolerance(ref ListBox lBox, ref List<Toler> list)
		{
			InitializeComponent();
			m_lBox = lBox;
			m_List = list;
		}

		public void getTol()
		{
			this.ShowDialog();
			return;
		}

		private void addTol()
		{
			if (txtTol.Text == "")
			{
				MessageBox.Show("Enter a tolerance value");
			}
			else if (txtTol.Text != "")
			{
				try
				{
					double TolInt = double.Parse(txtTol.Text);
					m_lBox.Items.Add(txtTol.Text);
					Toler t = new Toler(TolInt);
					m_List.Add(t);
				}
				catch (Exception)
				{
					MessageBox.Show("Tolerance must be a double.\nExpressed either as the exponential notation e,\nor using a decimal point");
				}
			}
		}

		private void butAdd_Click(object sender, EventArgs e)
		{
			addTol();
			this.Close();
		}

		private void butCancel_Click(object sender, EventArgs e)
		{		
			this.Close();
		}
	}
}